package com.zfk.transaction.config;

/**
 * Author : zfk
 * Date : 10:54
 */
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/*
 * Author : zfk
 * Date : 14:46
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2) // 指定api类型为swagger2
                .apiInfo(apiInfo()) // 用于定义api文档汇总信息,即下面的配置
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) // 指定controller类,即加了Api注解的类
                .paths(PathSelectors.any()) // 选择所有controller
                .build();
    }

    //构建api文档的相关信息
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                // 页面标题
                .title("JPATest API Doc")
                // 描述
                .description("This is a restful api document of nc server.")
                //版本号
                .version("1.0")
                .build();
    }

}

